package tp.pr2;

public class Interpreter {
	
	public static Instruction generateInstruction(java.lang.String line)
	{
		
		String auxline[]=line.split(" ");
		auxline[0]=auxline[0].toUpperCase();
		
         if(auxline.length==1 &&
			(auxline[0].equals("HELP") || auxline[0].equals("MOVE") || auxline[0].equals("QUIT")|| auxline[0].equals("SCAN")))
			{  
				Instruction instruction = new Instruction(Action.valueOf(auxline[0]));
				return instruction;					
			}		
		 else if(auxline.length==2 &&
			 auxline[0].equals("TURN"))
			  {
			    auxline[1]=auxline[1].toUpperCase(); 
			    if(auxline[1].equals("LEFT") || auxline[1].equals("RIGHT"))
			      {
			    	Instruction instruction = new Instruction(Action.valueOf(auxline[0]),Rotation.valueOf(auxline[1]));
			    	return instruction;
			      }
			     else
			      { 	
			        Instruction instruction = new Instruction(Action.valueOf(auxline[0]));
					return instruction;		
			      }
		      }
         
        else if (auxline.length==2 &&
				 (auxline[0].equals("PICK") || auxline[0].equals("OPERATE") ||auxline[0].equals("SCAN")))
              {
        	    Instruction instruction = new Instruction(Action.valueOf(auxline[0]),auxline[1]);
        	    return instruction;
              }
		else
		    {
			 Instruction instruction= new Instruction();
			 return instruction;
		    }
	}
	
	
	public static java.lang.String interpreterHelp()
	{
		String LINE_SEPARATOR = System.getProperty("line.separator");
		return("The valid instructions for WALL-E are:"+LINE_SEPARATOR +
			"     MOVE"+LINE_SEPARATOR +
			"     TURN <LEFT | RIGHT>"+LINE_SEPARATOR +
			"     PICK <id>"+LINE_SEPARATOR +
			"     SCAN [ <id> ]"+LINE_SEPARATOR +
			"     OPERATE <id>"+LINE_SEPARATOR +
			"     HELP"+LINE_SEPARATOR +
			"     QUIT"+LINE_SEPARATOR);
	}	  	

}
